package com.lianniu.web.baseService.area.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import com.lianniu.web.base.BaseResult;
import com.lianniu.web.baseService.area.dao.ISystemAreaMapperDao;
import com.lianniu.web.baseService.area.model.SystemAreaVo;
import com.lianniu.web.baseService.area.service.ISystemAreaService;
import com.lianniu.web.constants.ErrorCode;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

/**
 * @ClassName：类名
 * @Description:类的功能描述

 * @Since: 作成日期
 * @Version:版本
 */
@Service
public class SystemAreaServiceImpl implements ISystemAreaService {
  private final static Logger logger = Logger.getLogger(SystemAreaServiceImpl.class);
  @Resource
  private ISystemAreaMapperDao systemAreaDao;

  @Override
  public BaseResult getAllSysArea() {
    logger.info("getAllSysArea begin");
    List<SystemAreaVo> list = systemAreaDao.getAllSysArea();
    logger.info("getAllSysArea end");
    return BaseResult.success(list);
  }

  @Override
  public BaseResult getParentSysAreaByAreaId(String areaId) {
    logger.info("getParentSysAreaByAreaId begin");
    logger.info("areaId:" + areaId);
    SystemAreaVo vo = systemAreaDao.getParentSysAreaByAreaId(areaId);
    logger.info("getParentSysAreaByAreaId end");
    return BaseResult.success(vo);
  }

  @Override
  public BaseResult getSysAreaByAreaId(String areaId) {
    logger.info("getSysAreaByAreaId begin");
    logger.info("areaId:" + areaId);
    SystemAreaVo vo = systemAreaDao.getSysAreaByAreaId(areaId);
    logger.info("getSysAreaByAreaId end");
    return BaseResult.success(vo);
  }

  @Override
  public BaseResult addSysArea(SystemAreaVo areaVo) {
    logger.info("addSysArea begin");
    logger.info("asAreaInfoVo:" +JSON.toJSONString(areaVo));
    int result=systemAreaDao.addSysArea(areaVo);
    logger.info("addSysArea end");
    return BaseResult.success(result);
  }

  @Override
  public BaseResult editSysArea(SystemAreaVo areaVo) {
    logger.info("editSysArea begin");
    logger.info("asAreaInfoVo:" +JSON.toJSONString(areaVo));
    int result=systemAreaDao.editSysArea(areaVo);
    logger.info("editSysArea end");
    return BaseResult.success(result);
  }

@Override
public BaseResult isExistSysAreaCode(String id, String areaCode) {
	logger.info("isExistSysAreaCode begin");
	int num = systemAreaDao.isExistSysAreaCode(id,areaCode);
	logger.info("isExistSysAreaCode end");
	if(num>0){
		return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	}
	return BaseResult.success(num);
}

}
